import request from "@/utils/request";
import type { typePageInfo } from "@/api/trademark";

//类型1-1:  请求1 返回值 类型
export type typeGetSPUInfo = typePageInfo<typeGetSPUInfoDetailList[]>;
//类型1-2:  请求1 返回值内 records数组类型
export interface typeGetSPUInfoDetailList {
  id: number;
  spuName: string;
  description: string;
  category3Id: number;
  tmId: number;
}
//请求1:  获取SPU列表
export const reqGetSPUInfoList = (page = 1, limit = 5, category3Id: number) => {
  return request.get<any,typeGetSPUInfo>(`/product/${page}/${limit}`, { params: { category3Id } });
};



//类型2-1 请求2 参数类型
export interface typeSaveSpuInfo{
  category3Id:number,
  spuName:string,
  tmId:number,
  description:string,
  spuImageList:spuImage[],
  spuSaleAttrList:spuSaleAttr[]
}
//类型2-2: spuImage类型
export interface spuImage{
  imgName:string,
  imgUrl:string
}
//类型2-3:spuSaleAttr类型
export interface spuSaleAttr{
  baseSaleAttrId:number,
  saleAttrName:string,
  spuSaleAttrValueList:spuSaleAttrValue[],
  isEdit?: boolean;
}
//类型2-4:spuSaleAttrValue类型
export interface spuSaleAttrValue{
  baseSaleAttrId:number,
  saleAttrName:string,
  saleAttrValueName:string
}
//请求2:  添加SPU
export const reqSaveSpuInfo = (data:typeSaveSpuInfo)=>{
  return request.post<any,any>(`/product/saveSpuInfo`,data)
}

//类型3-1:  基础销售属性类型
export interface ResBaseSaleAttr {
  id: number;
  name: string;
}
//请求3:  获取基础销售属性列表
export const reqBaseSaleAttrListInfo = ()=>{
  return request.get<any,ResBaseSaleAttr[]>(`/product/baseSaleAttrList`)
}

/**
 * 获取SPU的销售属性列表
 */
export interface ResBaseSaleAttr {
  id: number;
  name: string;
}

export interface ResSpuImage extends spuImage {
  id: number;
  spuId: number;
}

export type ResSpuSaleAttrValue = spuSaleAttrValue & {
  id: number;
  spuId: number;
};
export type ResSpuSaleAttr = Omit<
spuSaleAttr,
  "spuSaleAttrValueList"
> & {
  id: number;
  spuId: number;
} & {
  spuSaleAttrValueList: ResSpuSaleAttrValue[];
};
export type ReqUpdateSpuInfo = Omit<
typeSaveSpuInfo,
  "spuImageList" | "spuSaleAttrList"
> & {
  id: number;
} & {
  spuImageList: (spuImage & {
    id?: number;
    spuId?: number;
  })[];
} & {
  spuSaleAttrList: (Omit<spuSaleAttr, "spuSaleAttrValueList"> & {
    id?: number;
    spuId?: number;
  } & {
    spuSaleAttrValueList: (spuSaleAttrValue & {
      id?: number;
      spuId?: number;
    })[];
  })[];
};
export function requestSpuSaleAttrList(id: number) {
  return request.get<any, ResSpuSaleAttr[]>(`/product/spuSaleAttrList/${id}`);
}


export interface ResSPU {
  id: number;
  category3Id: number;
  tmId: number;
  spuName: string;
  description: string;
}

/**
 * 获取SPU的图片列表
 */
export function requestSpuImageList(id: number) {
  return request.get<any, ResSpuImage[]>(`/product/spuImageList/${id}`);
}